08. K-means Application Demo

Cd13639 C1 L2 DEMO 3 V1

Applying K-means to Stock Market Data

This demo explains how K-means clustering can help identify patterns in stock market data. The goal is to discover correlations between mean returns and standard deviation among stocks using this method.

Steps:

  1. Dataset Preparation
    • Use the total returns dataset
    • Group data by ticker to analyze individual stock characteristics
    • Compute the mean return and standard deviation per ticker
  2. Data Scaling
    • Standardize the dataset using the standard scaler to achieve comparable data
  3. Determine Optimal Clusters
    • Use the elbow method to decide the ideal number of clusters by evaluating the sum of squared errors
    • Visualize a range of clusters (up to 11) and identify the optimal cluster point
  4. Perform K-means Clustering
    • Run K-means with the chosen cluster number
  5. Analysis
    • Assign each stock to a cluster and visualize clusters on a scatter plot
    • Identify patterns: correlate higher returns with higher standard deviations

This approach aids in systematic stock analysis and pattern recognition, offering insights for future investments.